﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.BLL
{
    public class StockInType
    {
        #region 封装属性

        private int mStockInTypeNum;

        public int StockInTypeNum
        {
            get { return mStockInTypeNum; }
            set { mStockInTypeNum = value; }
        }

        private string mStockInTypeName;

        public string StockInTypeName
        {
            get { return mStockInTypeName; }
            set { mStockInTypeName = value; }
        }

        private string mStockInTypeCode;

        public string StockInTypeCode
        {
            get { return mStockInTypeCode; }
            set { mStockInTypeCode = value; }
        }

        #endregion

        private IStockInTypeDAL stockintypeDAL;

        public StockInType()
        {
            stockintypeDAL = Adapter.GetStockInType();
        }

        public void FetchObject(IDataReader dr)
        {
            if (dr!=null)
            {
                mStockInTypeNum = ConvertDataType.CheckFiledInt(dr["stock_in_type_num"]);
                mStockInTypeName = ConvertDataType.CheckFiledString(dr["stock_in_type_name"]);
                mStockInTypeCode = ConvertDataType.CheckFiledString(dr["stock_in_type_code"]);
            }
        }


        public StockInType GetStockInType(string name)
        {
            StockInType obj = new StockInType();
            IDataReader dr = stockintypeDAL.Select(name);
            while (dr != null && dr.Read())
            {
                obj.FetchObject(dr);
            }
            return obj;
        }

        public DataTable Display()
        {
            return stockintypeDAL.SelectAll();
        }

        public bool CreateStockInType(StockInType stockInType)
        {
            return stockintypeDAL.Insert(stockInType.mStockInTypeName, stockInType.mStockInTypeCode) > 0 ? true : false;
        }

        public bool SetStockInType(StockInType stockInType)
        {
            return stockintypeDAL.Update(stockInType.mStockInTypeNum, stockInType.mStockInTypeName, stockInType.mStockInTypeCode) > 0 ? true : false;
        }

        public bool RemoveStockInType(int stockInTypeNum)
        {
            return stockintypeDAL.Delete(stockInTypeNum) > 0 ? true : false;
        }

        public IList<StockInType> GetAllStockInType()
        {
            IList<StockInType> list = new List<StockInType>();
            IDataReader dr = stockintypeDAL.Select();
            while (dr != null && dr.Read())
            {
                StockInType stockInType = new StockInType();
                stockInType.FetchObject(dr);
                list.Add(stockInType);
            }
            if (dr != null) dr.Close();
            return list;
        }
    }
}
